package com.itheima.img;

import com.itheima.common.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author ChenJunJie
 * @date 2022/6/14 14:30
 * 图片上传的controller层
 */
@RestController
@RequestMapping(value = "/common", produces = "application/json;charset=utf-8")
public class ImagesController {

    @Autowired
    private ImagesService imagesService;
    @Autowired
    private RedisTemplate<String, String> redisTemplate;
    // 上传图片
    @PostMapping("/upload")
    public JsonResult<String> img(@RequestParam("file") MultipartFile multipartFile) {

        if (multipartFile.isEmpty()) {
            return JsonResult.error("文件为空!");
        }

        // String token = request.getHeader("Authorization");
        // String username = redisTemplate.opsForValue().get(token);
        String username= "admin";

        return imagesService.uploadfile(multipartFile, username);

    }
}
